﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MyFace
{
    class Botao
    {
        Texture2D TexBotao;
        Texture2D TexSeta;
        Vector2 PosSeta = new Vector2(0,0);
        Boolean BoolSeta = false;
        public Rectangle recBotao;
        String nomeTexturaBotao;
        int ParaSumir = 0;
        string PosicaoSeta;
        float Rotacao;
        public bool MouseOver = false;
        short LangIndex = 0;

        public Botao(String nomeTexturaBotao, Rectangle recBotao, short langIndex)
        {
            this.nomeTexturaBotao = nomeTexturaBotao;
            this.recBotao = recBotao;
            this.LangIndex = langIndex;
        }              

        public void Load(ContentManager Content)
        {
            TexBotao = Content.Load<Texture2D>(nomeTexturaBotao);
            TexSeta = Content.Load<Texture2D>("seta");
        }

        public void Update(GameTime gameTime, string PosicaoDaSeta)
        {
            this.PosicaoSeta = PosicaoDaSeta;

            if (recBotao.Contains(Cursor.X, Cursor.Y))
            {
                MouseOver = true;
                BoolSeta = true;
                switch (PosicaoSeta)
                {
                    case "Esquerda":
                        PosSeta.X = recBotao.X - TexSeta.Width;
                        PosSeta.Y = recBotao.Y + (TexBotao.Height / 2 - TexSeta.Height / 2);
                        break;
                    case "Direita":
                        PosSeta.X = recBotao.X + recBotao.Width;
                        PosSeta.Y = recBotao.Y + (TexBotao.Height / 2 - TexSeta.Height / 2);
                        Rotacao = 0;
                        break;
                    case "Baixo":
                        PosSeta.X = recBotao.X + (recBotao.Width / 2 + TexSeta.Width / 2);
                        PosSeta.Y = recBotao.Y - TexSeta.Height - (TexSeta.Height/3.5f);
                        Rotacao = 90;
                        break;
                    case "Cima":
                        PosSeta.X = recBotao.X + recBotao.Width / 2;
                        PosSeta.Y = recBotao.Y + TexSeta.Height * 3.5f;
                        Rotacao = -90;
                        break;
                }

            }
            else
            {
                MouseOver = false;
                BoolSeta = false;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(TexBotao, recBotao, Color.White);
            try
            {
                spriteBatch.DrawString(Game1.Font, TextReader.lines[LangIndex], new Vector2(recBotao.X + 5, recBotao.Y + 5), Color.Black);
            }
            catch
            {
                spriteBatch.DrawString(Game1.Font, "N/A", new Vector2(recBotao.X + 5, recBotao.Y + 5), Color.Red);
            }
            if (BoolSeta)
            {
                switch (PosicaoSeta)
                {
                    case "Esquerda":
                        spriteBatch.Draw(TexSeta, PosSeta, Color.White);
                        break;

                    case "Direita":
                        spriteBatch.Draw(TexSeta, new Rectangle((int)PosSeta.X, (int)PosSeta.Y, TexSeta.Width, TexSeta.Height), new Rectangle(0, 0, TexSeta.Width, TexSeta.Height), Color.White, Rotacao, new Vector2(), SpriteEffects.FlipHorizontally, 0);
                        break;

                    case "Baixo":
                        spriteBatch.Draw(TexSeta, new Rectangle((int)PosSeta.X, (int)PosSeta.Y, TexSeta.Width, TexSeta.Height), new Rectangle(0, 0, TexSeta.Width, TexSeta.Height), Color.White, Rotacao, new Vector2(), SpriteEffects.FlipVertically, 0);
                        break;

                    case "Cima":
                        spriteBatch.Draw(TexSeta, new Rectangle((int)PosSeta.X, (int)PosSeta.Y, TexSeta.Width, TexSeta.Height), new Rectangle(0, 0, TexSeta.Width, TexSeta.Height), Color.White, Rotacao, new Vector2(), SpriteEffects.FlipVertically, 0);
                        break;
                }
            }            
        }
    }
}
